package com.gxa.jjty.admin.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.jjty.admin.service.OrderCancelService;
import com.gxa.jjty.core.common.JsonResult;

import com.gxa.jjty.core.pojo.OrderCancel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

@Log4j2
@Api(tags = "订单取消配置")
@RestController
@RequestMapping("/orderCancel")
@Validated
public class OrderCancelController {

    @Autowired
    OrderCancelService orderCancelService;

    @PostMapping("/add")
    @ApiOperation("订单取消配置的添加")
    public Map<String,Object> add(@RequestBody OrderCancel orderCancel){
        OrderCancel insert = orderCancelService.insert(orderCancel);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @PostMapping("/delete")
    @ApiOperation("订单取消配置的删除")
    public Map<String,Object> delete(@RequestParam(name = "id") Long id){
        Integer integer = orderCancelService.deleteById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @PostMapping("/selectAll")
    @ApiOperation("订单取消配置的全查询")
    public Map<String,Object> selectAll(){
        List<OrderCancel> orderCancels = orderCancelService.selectAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(orderCancels);
        return jsonResult.getDataMap();
    }
    @PostMapping("/selectByPage")
    @ApiOperation("订单取消配置的分页查询")
    public Map<String,Object> selectByPage(@RequestParam(name = "page") Integer page,@RequestParam(name = "size") Integer size) throws IllegalAccessException {
        PageInfo<OrderCancel> orderCancelPageInfo = orderCancelService.selectByPage(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }
    @PostMapping("/update")
    @ApiOperation("订单取消配置的修改")
    public Map<String,Object> update(OrderCancel orderCancel) throws IllegalAccessException {
        Integer integer = orderCancelService.updateById(orderCancel);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }


 @PostMapping("}selectByField")
 @ApiOperation("订单取消配置的条件查询")
    public Map selectByField(Integer page,Integer size,String reason,String state) throws IllegalAccessException {

     OrderCancel orderCancel = new OrderCancel();
     orderCancel.setReason(reason);
     orderCancel.setState(state);
     PageInfo<OrderCancel> orderCancelPageInfo = orderCancelService.selectByPage(page, size, orderCancel);
     JsonResult jsonResult = new JsonResult();
     jsonResult.setCode("1");
     jsonResult.setData(orderCancelPageInfo.getTotal());
     return jsonResult.getDataMap();
 }



}
